<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>jQuery的scrollTop方法</title>
    <style>
        div{
            width:100px;
            height:250px;
            border:1px solid black;
            overflow:auto;
        }
    </style>
    <script src="./js/jquery-1.12.4.js"></script>
    <script>
      $(function(){
          var btns = document.getElementsByTagName('button')
          btns[0].onclick = function(){
              console.log($("div").scrollTop())    //获取当前滚动条和顶部的距离，偏移位
          }
          btns[1].onclick = function(){
              $("div").scrollTop(300)    //设置当前滚动条和顶部的距离为300，偏移位
              console.log($("div").scrollTop())    //打印滚动条和顶部的距离，偏移位
          }
      })
    </script>
</head>
<body>
    <div>超长div超长div超长div超长div超长div超长div超长div超长div超长div超长div超长div超长div
        超长div超长div超长div超长div超长div超长div超长div超长div超长div超长div超长div超长div超长div
        超长div超长div超长div超长div超长div超长div超长div超长div超长div超长div超长div超长div超长div
        超长div超长div超长div超长div超长div超长div超长div超长div超长div超长div超长div超长div超长div
        超长div超长div超长div超长div超长div超长div超长div超长div超长div超长div超长div超长div超长div
    </div>
    <button>获取</button>
    <button>设置</button>
</body>
</html>